package com.smz.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smz.dao.CustomerDAO;
import com.smz.entity.Customer;
import com.smz.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;


@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerDAO, Customer> implements CustomerService {

    @Autowired
    CustomerDAO customerDAO;

    @Override
    public IPage<Customer> findCustomerBySuppName(int current, int size) {
        User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return customerDAO.selectCustomerBySuppName(new Page(current,size),principal.getUsername());
    }

    @Override
    public IPage<Customer> selectCustomerLike(int current, int size, String name, String address) {
        return customerDAO.selectCustomerLike(new Page(current,size),"%"+name+"%","%"+address+"%");
    }
}
